package com.zdxf.controller;

import com.zdxf.conf.Constant;
import com.zdxf.service.impl.MonitorServiceImpl;
import com.zdxf.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@Api(tags = "系统消息指标")
@RestController
@RequestMapping("/monitor")
public class MonitorController {
    @Autowired
    MonitorServiceImpl monitorService;

    @ApiOperation(value = "CPU使用率", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", required = false, paramType = "query"),
    })
    @GetMapping(value = "/getCpuInfo")
    public Object getCpuInfo(HttpServletRequest request) {
        HashMap<String, String> params = new HashMap<>(Constant.HASH_MAP_SIZE);
        params.put("id", request.getParameter("id"));
        return new Result(true, 20000, "success", monitorService.getCpuInfoList(params));
    }

    @ApiOperation(value = "内存使用率", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", required = false, paramType = "query"),
    })
    @GetMapping(value = "/getMemInfo")
    public Object getMemInfo(HttpServletRequest request) {
        HashMap<String, String> params = new HashMap<>(Constant.HASH_MAP_SIZE);
        params.put("id", request.getParameter("id"));
        return new Result(true, 20000, "success", monitorService.getMemInfoList(params));
    }

    @ApiOperation(value = "硬盘使用率", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", required = false, paramType = "query"),
    })
    @GetMapping(value = "/getDiskInfo")
    public Object getDiskInfo(HttpServletRequest request) {
        HashMap<String, String> params = new HashMap<>(Constant.HASH_MAP_SIZE);
        params.put("id", request.getParameter("id"));
        return new Result(true, 20000, "success", monitorService.getDiskInfoList(params));
    }

    @ApiOperation(value = "网络流量", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", required = false, paramType = "query"),
    })
    @GetMapping(value = "/getNetInfo")
    public Object getNetInfo(HttpServletRequest request) {
        HashMap<String, String> params = new HashMap<>(Constant.HASH_MAP_SIZE);
        params.put("id", request.getParameter("id"));
        return new Result(true, 20000, "success", monitorService.getDNetInfoList(params));
    }

    @ApiOperation(value = "系统信息", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", required = false, paramType = "query"),
    })
    @GetMapping(value = "/getSysInfo")
    public Object getSysInfo(HttpServletRequest request) {
        HashMap<String, String> params = new HashMap<>(Constant.HASH_MAP_SIZE);
        params.put("id", request.getParameter("id"));
        return new Result(true, 20000, "success", monitorService.getSysInfoList(params));
    }

    @ApiOperation(value = "集群CPU使用率", notes = "")
    @GetMapping(value = "/getCpuInfoSum")
    public Object getCpuInfoSum() {
        return new Result(true, 20000, "success", monitorService.getCpuInfoSum());
    }

    @ApiOperation(value = "集群内存使用率", notes = "")
    @GetMapping(value = "/getMemInfoSum")
    public Object getMemInfoSum() {
        return new Result(true, 20000, "success", monitorService.getMemInfoSum());
    }

    @ApiOperation(value = "集群硬盘使用率", notes = "")
    @GetMapping(value = "/getDiskInfoSum")
    public Object getDiskInfoSum() {
        return new Result(true, 20000, "success", monitorService.getDiskInfoSum());
    }

    @ApiOperation(value = "集群网络流量", notes = "")
    @GetMapping(value = "/getNetInfoSum")
    public Object getNetInfoSum() {
        return new Result(true, 20000, "success", monitorService.getNetInfoSum());
    }

    @ApiOperation(value = "集群系统负载", notes = "")
    @GetMapping(value = "/getCpuLoadSum")
    public Object getCpuLoadSum() {
        return new Result(true, 20000, "success", monitorService.getCpuLoadSum());
    }

    @ApiOperation(value = "获取除网络之外的全部信息", notes = "")
    @GetMapping(value = "/getAllInfo")
    public Object getAllInfo() {
        return new Result(true, 20000, "success", monitorService.getAllInfo());
    }

}
